package com.hongxun.modules.csg.controller;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.List;

import com.hongxun.common.utils.*;
import com.hongxun.common.validator.ValidatorUtils;
import com.hongxun.common.validator.group.UpdateGroup;
import com.hongxun.modules.bss.entity.DPictureEntity;
import com.hongxun.modules.bss.service.DPictureService;
import com.hongxun.modules.csg.entity.CGoodsDetailEntity;
import com.hongxun.modules.csg.entity.CPBaseEntity;
import com.hongxun.modules.csg.entity.CStackPointEntity;
import com.hongxun.modules.csg.service.CGoodsDetailService;
import com.hongxun.modules.csg.service.CPBaseService;
import com.hongxun.modules.csg.service.CStackPointService;
import com.hongxun.modules.sys.entity.SysUserEntity;
import com.hongxun.modules.sys.service.ShiroService;
import com.lowagie.text.*;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.csg.entity.CArrivalRecordEntity;
import com.hongxun.modules.csg.service.CArrivalRecordService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 到货记录
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-09-11 09:30:52
 */
@RestController
@RequestMapping("/csg/carrivalrecord")
public class CArrivalRecordController {
	@Autowired
	private CArrivalRecordService cArrivalRecordService;
	@Autowired
	private CStackPointService cStackPointService;
	@Autowired
	protected ShiroService shiroService;
	@Autowired
	private CGoodsDetailService cGoodsDetailService;
	@Value("${com.hongxun.IMAGEROTT}")
	private String ROOT;
	@Autowired
	private CPBaseService cPBaseService;
	@Autowired
	private DPictureService dPictureService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
        //1.根据项目名称查询对应到货记录duifangPGuid
//		List<CArrivalRecordEntity> cArrivalRecordList = new ArrayList<>();
//		List<CGoodsDetailEntity> cGoodsDetailList = new ArrayList<CGoodsDetailEntity>();

		List cArrivalRecordList = new ArrayList<>();
		List cGoodsDetailList = new ArrayList<CGoodsDetailEntity>();

		Map<String , Object> map = new HashMap<>();
		if (params.get("pGuid")!= null && !params.get("pGuid").toString().equals("")) {
			wheres += " and p_guid='" + params.get("pGuid") + "'";

			if (params.get("stack") != null && !params.get("stack").toString().equals("")) {
				wheres += " and s_p_guid='"+params.get("stack").toString()+"'";
			}
			if (params.get("time") != null && !params.get("time").toString().equals("")) {
				wheres += " and a_r_time like'%"+params.get("time").toString()+"%'";
			}
			if (params.get("wuzi") != null && !params.get("wuzi").toString().equals("")) {
				String wuziwheres = " 1=1 and g_d_bigtype like'%"+params.get("wuzi").toString()+"%'";
				map.put("filterSql",wuziwheres+" ");
				cGoodsDetailList = cGoodsDetailService.queryList(map);

			}

			query.put("filterSql",wheres+" ");
			cArrivalRecordList = cArrivalRecordService.queryList(query);
			cArrivalRecordList.addAll(cGoodsDetailList);
		}else{
			//2.查询所有到货记录
			wheres += " and 1=2 ";
			query.put("filterSql",wheres+" ");
			cArrivalRecordList = cArrivalRecordService.queryList(query);
		}
		int total = cArrivalRecordService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(cArrivalRecordList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil).put("cGoodsDetailList",cGoodsDetailList);

	}


	@RequestMapping("/select")
	public R info(@RequestParam Map<String , Object> params){

		//查询列表数据
		Query query = new Query(params);
		List<CArrivalRecordEntity> cArrivalRecordEntities = cArrivalRecordService.queryList(query);

		//到货记录--物资清单
		if (params.get("guid")!=null && !params.get("guid").toString().equals("")) {
			CArrivalRecordEntity cArrivalRecordEntity = cArrivalRecordService.queryObject(params.get("guid").toString());
			CStackPointEntity cStackPointEntity = cStackPointService.queryObject(cArrivalRecordEntity.getSPGuid());
			for (CArrivalRecordEntity arrivalRecordEntity : cArrivalRecordEntities) {
				arrivalRecordEntity.setSPName(cStackPointEntity.getSPName());
			}
		}

		//堆放点--物资清单
		if (params.get("sPGuid")!=null && !params.get("sPGuid").toString().equals("")) {
			CStackPointEntity cStackPointEntity = cStackPointService.queryObject(params.get("sPGuid").toString());
			for (CArrivalRecordEntity arrivalRecordEntity : cArrivalRecordEntities) {
				arrivalRecordEntity.setSPName(cStackPointEntity.getSPName());
			}
		}

		return R.ok().put("returnlist", cArrivalRecordEntities);
	}




	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		CArrivalRecordEntity cArrivalRecord = cArrivalRecordService.queryObject(guid);
		
		return R.ok().put("cArrivalRecord", cArrivalRecord);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody CArrivalRecordEntity cArrivalRecord){
		cArrivalRecordService.save(cArrivalRecord);
		
		return R.ok();
	}


	/**
	 * 新增到货记录
	 *
	 * @param cArrivalRecord
	 * @param sPGuid
	 * @param pGuid
	 * @return
	 */
	@RequestMapping("/saveNew/{sPGuid}/{pGuid}")
	public R save(@RequestBody CArrivalRecordEntity cArrivalRecord ,
				  @PathVariable String sPGuid ,
				  @PathVariable String pGuid , HttpServletRequest request)
	{

		//从header中获取token
		String token = request.getHeader("token");
		//如果header中不存在token，则从参数中获取token
		if(StringUtils.isBlank(token)){
			token = request.getParameter("token");
		}
		SysUserEntity sysUserEntity = shiroService.queryByToken(token);

		if (sPGuid != null && !sPGuid.equals("") && !sPGuid.equals("undefined")) {
			cArrivalRecord.setSPGuid(sPGuid);
		}else{
			cArrivalRecord.setSPGuid(cArrivalRecord.getSPGuid());
		}
		cArrivalRecord.setARUser(sysUserEntity.getUserId());
		cArrivalRecord.setARUsername(sysUserEntity.getUsername());
		cArrivalRecord.setPGuid(pGuid);
		cArrivalRecord.setARDatastate("新增");
		cArrivalRecordService.save(cArrivalRecord);

		return R.ok();
	}




	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody CArrivalRecordEntity cArrivalRecord){
		ValidatorUtils.validateEntity(cArrivalRecord, UpdateGroup.class);
		cArrivalRecordService.update(cArrivalRecord);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		cArrivalRecordService.deleteBatch(guids);
		
		return R.ok();
	}







	/**
	 * 物资汇总
	 *
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws DocumentException
	 */
	@RequestMapping("/exports")
	public void exports(HttpServletRequest request , HttpServletResponse response) throws IOException, DocumentException {

		Map<String , Object> cStackPointMap = new HashMap<>();
		Map<String , Object> cSMap = new HashMap<>();

		//项目ID
		String pGuid = request.getParameter("pGuid");
		String cStackPointWhere = " 1=1 and p_guid='"+pGuid+"'";
		cStackPointMap.put("filterSql" , cStackPointWhere);
		List<CArrivalRecordEntity> cArrivalRecordEntityList= cArrivalRecordService.queryList(cStackPointMap);

		//根据堆放点分组
		String cStWhere = " 1=1 and p_guid='"+pGuid+"'";
		cSMap.put("filterSql" , cStWhere);
		List<CArrivalRecordEntity> cArList= cArrivalRecordService.queryListToSPName(cSMap);


//		CStackPointEntity cStackPoint = cStackPointService.queryObject(guid);
		//项目名称
//		String pGuid = cStackPoint.getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);
		//设置下载文件的格式(表格)msword
//		response.setContentType("application/vnd.ms-excel;charset=utf-8");//表格
		response.setContentType("application/msword;charset=utf-8");//文档
		try {
//			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cStackPoint.getSPName()==null?"堆放点材料":cStackPoint.getSPName()) + ".xlsx").getBytes(), "iso-8859-1"));
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cpBaseEntity.getPBName()==null?"堆放点材料":cpBaseEntity.getPBName()+"到货记录") + ".doc").getBytes(), "iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		//A4纸横向打印
		Document document = new Document(PageSize.A4.rotate());
		//字体设置
		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

		RtfWriter2.getInstance(document, response.getOutputStream());
		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
		footer.setAlignment(1);
		footer.setBorder(Rectangle.NO_BORDER);
		document.setFooter(footer);
		document.open();
		//文件内容及格式
		setexports(document,bfChinese,cArrivalRecordEntityList , cArList);

		document.close();

	}

	/**
	 * 导出内容和文档样式
	 *
	 * @param document
	 * @param bfChinese
	 * @param
	 * @throws DocumentException
	 */
	public void setexports(Document document  ,BaseFont bfChinese ,	List<CArrivalRecordEntity> cArrivalRecordEntityList ,
						   List<CArrivalRecordEntity> cArList  ) throws DocumentException {

		Map<String, Object> cStackMap = new HashMap<>();
		String cStackWhere = " 1=1 ";
		//堆放点名称
//		String sPName = cStackPoint.getSPName();

		//1.查询所属堆放点下所有的到货记录
//		String cStackWhere = " 1=1 and s_p_guid='"+cStackPoint.getGuid()+"' and a_r_datastate != '删除' and p_guid='"+cStackPoint.getPGuid()+"'";
//		cStackMap.put("filterSql",cStackWhere);
//		List<CArrivalRecordEntity> cArrivalList = cArrivalRecordService.queryList(cStackMap);
//
//		cStackMap.remove("filterSql");
//		cStackWhere = cStackWhere.substring(0,4);


		//2.查询所属到货记录下的物资清单
		if (cArrivalRecordEntityList.size() != 0) {
			for (int i = 0; i < cArrivalRecordEntityList.size(); i++) {
				String guid = cArrivalRecordEntityList.get(i).getGuid();
				if (i == 0) {
					cStackWhere += " and a_r_guid = '" + guid + "' ";
				} else {
					cStackWhere += " or a_r_guid = '" + guid + "' ";
				}
			}
		}

		cStackMap.put("filterSql", cStackWhere + " ");
		List<CGoodsDetailEntity> cGoodsDetailList = cGoodsDetailService.queryList(cStackMap);

		//3.获取项目名称
		String pGuid = cArrivalRecordEntityList.get(0).getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);


		//表题字体
		Font titleFont = new Font(bfChinese, 11, Font.BOLD);
		//表格字体
		Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
		//签字字体
		Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
//		Paragraph title = new Paragraph("配网技改/修理项目申请书（适用于总投资100万元以下的配网技改/修理项目）");
//		title.setAlignment(Element.ALIGN_CENTER);
//		title.setFont(titleFont);
//		document.add(title);

//		Table table = new Table(13);
//		int[] withs = {1, 3, 3, 2, 2, 3,3, 2,2, 2, 2, 2,4};
		Table table = new Table(7);
		int[] withs = {1, 1, 1, 1, 1, 1, 1};
		table.setWidths(withs);
		/** 表格所占页面宽度 author:yyli Sep 15, 2010 */
		table.setWidth(90);
		/** 居中显示 author:yyli Sep 15, 2010 */
		table.setAlignment(Element.ALIGN_CENTER);
		/** 自动填满 author:yyli Sep 15, 2010 */
		table.setAutoFillEmptyCells(true);

		for (CArrivalRecordEntity cArr : cArList) {
			OutPutUtils.addcell(table, cpBaseEntity.getPBName() + "项目-"+cArr.getSPName()+"到货材料清单", 0, 7, true, contextFont);

			//材料清单列表
			OutPutUtils.addcell(table, "材料中类", 0, 0, true, contextFont);
			OutPutUtils.addcell(table, "材料名称", 0, 0, true, contextFont);
			OutPutUtils.addcell(table, "主要技术参数", 0, 0, true, contextFont);
			OutPutUtils.addcell(table, "到货数", 0, 0, true, contextFont);
			OutPutUtils.addcell(table, "单位", 0, 0, true, contextFont);
			OutPutUtils.addcell(table, "供货商", 0, 0, true, contextFont);
//			OutPutUtils.addcell(table, "所属堆放点", 0, 0, true, contextFont);
			OutPutUtils.addcell(table, "到货日期", 0, 0, true, contextFont);


			for (CArrivalRecordEntity cArrivalRecordEntity : cArrivalRecordEntityList) {
				if(cArrivalRecordEntity.getSPName().equals(cArr.getSPName())){
				for (CGoodsDetailEntity cGoodsDetailEntity : cGoodsDetailList) {
					//				String sPName = "";
					if (cGoodsDetailEntity.getARGuid().equals(cArrivalRecordEntity.getGuid())) {

						OutPutUtils.addcell(table, cGoodsDetailEntity.getGDMidtype(), 0, 0, true, contextFont);
						OutPutUtils.addcell(table, cGoodsDetailEntity.getGDName(), 0, 0, true, contextFont);
						OutPutUtils.addcell(table, cGoodsDetailEntity.getGDParameter(), 0, 0, true, contextFont);
						OutPutUtils.addcell(table, cGoodsDetailEntity.getGDNum().toPlainString(), 0, 0, true, contextFont);
						OutPutUtils.addcell(table, cGoodsDetailEntity.getGDUnit(), 0, 0, true, contextFont);
						OutPutUtils.addcell(table, cGoodsDetailEntity.getGDBusine(), 0, 0, true, contextFont);
//						OutPutUtils.addcell(table, cArrivalRecordEntity.getSPName(), 0, 0, true, contextFont);
						OutPutUtils.addcell(table, cArrivalRecordEntity.getARTime() == null ? "" : DateUtils.format(cArrivalRecordEntity.getARTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					}
				}
			}
			}
		}

		document.add(table);
	}







	/**
	 * 导出材料到场照片
	 *
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws DocumentException
	 */
	@RequestMapping("/exportsimg")
	public void exportsimg(HttpServletRequest request, HttpServletResponse response) throws IOException, DocumentException {

		Map<String , Object> imgMap = new HashMap<>();

		//堆放点
		String pGuid = request.getParameter("pGuid");
		String cStackPointWhere = " 1=1 and p_guid='"+pGuid+"'";
		imgMap.put("filterSql" , cStackPointWhere);
		List<CArrivalRecordEntity> cArrivalRecordEntityList= cArrivalRecordService.queryList(imgMap);
//		CStackPointEntity cStackPointEntity = cStackPointService.queryObject(guid);
		//项目名称
//		String pGuid = cStackPointEntity.getPGuid();
		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);

		response.setContentType("application/msword;charset=utf-8");
		try {
			response.setHeader("Content-Disposition", "attachment;filename=" + new String(((cpBaseEntity.getPBName()==null?"":cpBaseEntity.getPBName()) + "_材料照片.doc").getBytes(), "iso-8859-1"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}

		Document document = new Document();
		BaseFont bfChinese = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

		RtfWriter2.getInstance(document, response.getOutputStream());
		Font titleFontye = new Font(bfChinese,8,Font.BOLD);
		HeaderFooter footer = new HeaderFooter(new Phrase("页码：",titleFontye), true);
		footer.setAlignment(1);
		footer.setBorder(Rectangle.NO_BORDER);
		document.setFooter(footer);
		document.open();
		setexportsimg(document,bfChinese,cArrivalRecordEntityList , cpBaseEntity);

		document.close();
	}

	/**
	 * 设置表格格式
	 *
	 * @param document
	 * @param bfChinese
	 * @param
	 * @throws DocumentException
	 * @throws IOException
	 */
	public void setexportsimg(Document document  ,BaseFont bfChinese ,	List<CArrivalRecordEntity> cArrivalRecordEntityList ,CPBaseEntity cpBaseEntity  ) throws DocumentException, IOException {

		Map<String ,Object> cStackMap = new HashMap<>();
		//项目名称
//		String pGuid = cStackPointEntity.getPGuid();
//		CPBaseEntity cpBaseEntity = cPBaseService.queryObject(pGuid);

		//表题字体
		Font titleFont = new Font(bfChinese,11,Font.BOLD);
		//表格字体
		Font contextFont = new Font(bfChinese, 8, Font.NORMAL);
		// 签字字体
		Font qinFont = new Font(bfChinese, 10, Font.NORMAL);
		Paragraph title = new Paragraph((cpBaseEntity.getPBName()==null?"":cpBaseEntity.getPBName()) + "_材料照片");
		title.setAlignment(Element.ALIGN_CENTER);
		title.setFont(titleFont);
		document.add(title);

		//1.查询所属堆放点下所有的到货记录
		/*String cStackWhere = " 1=1 and s_p_guid='"+cStackPointEntity.getGuid()+"' and a_r_datastate != '删除' and p_guid='"+cStackPointEntity.getPGuid()+"'";
		cStackMap.put("filterSql",cStackWhere);
		List<CArrivalRecordEntity> cArrivalList = cArrivalRecordService.queryList(cStackMap);

		cStackMap.remove("filterSql");
		cStackWhere = cStackWhere.substring(0,4);


		//2.查询所属到货记录下的物资清单
		for (int i = 0; i < cArrivalList.size(); i++) {
			String aRguid = cArrivalList.get(i).getGuid();
			if (i == 0) {
				cStackWhere += " and a_r_guid = '"+aRguid+"' ";
			}else {
				cStackWhere += " or a_r_guid = '"+aRguid+"' ";
			}
		}

		cStackMap.put("filterSql",cStackWhere+" ");
		List<CGoodsDetailEntity> cGoodsDetailList = cGoodsDetailService.queryList(cStackMap);

		addCStackPointImg(document, cStackPointEntity, contextFont, cGoodsDetailList);*/




//		String cStackWhere = " 1=1 and guid='"+cStackPointEntity.getGuid()+"' and s_p_datastate != '删除' and p_guid='"+cStackPointEntity.getPGuid()+"'";
//		cStackMap.put("filterSql",cStackWhere);
//		List<CStackPointEntity> cStackPointEntityList = cStackPointService.queryList(cStackMap);

		addCStackPointImg(document, contextFont, cArrivalRecordEntityList , cpBaseEntity);

	}

	/**
	 *
	 *
	 * @param document
	 * @param
	 * @param contextFont
	 * @param
	 * @throws DocumentException
	 * @throws IOException
	 */
	private void addCStackPointImg(Document document,Font contextFont, List<CArrivalRecordEntity> cArrivalRecordEntityList , CPBaseEntity cpBaseEntity) throws DocumentException, IOException {

		for (CArrivalRecordEntity cArrivalRecordEntity : cArrivalRecordEntityList) {

			Map<String , Object> cGoodsDetailMap = new HashMap<>();
			String cScheduleWhere = " 1=1 and p_guid= '"+cArrivalRecordEntity.getPGuid()+
					"' and p_status = '施工' and p_label like'%材料%'" +
					" and p_p_guid='"+cArrivalRecordEntity.getGuid()+"' and p_datastate !='删除' ";
			cGoodsDetailMap.put("filterSql", cScheduleWhere + " ");
			List<DPictureEntity> dPictureList = dPictureService.queryList(cGoodsDetailMap);
			if(dPictureList.size()>0) {

				Table table = new Table(6);
				int[] withs = {1, 2, 1, 2, 1, 2};
				table.setWidths(withs);
				/** 表格所占页面宽度 author:yyli Sep 15, 2010 */
				table.setWidth(90);
				/** 居中显示 author:yyli Sep 15, 2010 */
				table.setAlignment(Element.ALIGN_CENTER);
				/** 自动填满 author:yyli Sep 15, 2010 */
				table.setAutoFillEmptyCells(true);

				OutPutUtils.addcell(table, cpBaseEntity.getPBName() + "(材料)", 0, 6, true, contextFont);
				int chishu = dPictureList.size() / 3;
				int yushu = dPictureList.size() % 3;

				if (yushu > 0) {
					chishu = chishu + 1;
				}
				//一行显示3张照片
				for (int i = 0; i < chishu;i++) {
					boolean one = false;
					boolean two = false;
					boolean three = false;

					if ((3 * i) < dPictureList.size() ) {
						one = true;
					}
					if (((3 * i) + 1) < dPictureList.size()) {
						two = true;
					}
					if (((3 * i) + 2) < dPictureList.size()) {
						three = true;
					}
					if (one) {
						File file=new File(ROOT +   dPictureList.get(3 * i).getPServeraddress());
						if(file.exists()) {
							OutPutUtils.addcellimg(table, ROOT +   dPictureList.get(3 * i).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}
					if (two) {
						File file=new File(ROOT +   dPictureList.get((3 * i)+1).getPServeraddress());
						if(file.exists()) {
							OutPutUtils.addcellimg(table, ROOT +   dPictureList.get((3 * i)+1).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}
					if (three) {
						File file=new File(ROOT +   dPictureList.get((3 * i)+2).getPServeraddress());
						if(file.exists()) {
							OutPutUtils.addcellimg(table, ROOT +   dPictureList.get((3 * i)+2).getPServeraddress(), 8, 2, true, contextFont);
						} else {
							OutPutUtils.addcell(table, "没找到照片", 8, 2, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 8, 2, true, contextFont);
					}

					//照片名称
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (one) {
						if (dPictureList.get(3 * i).getPLabel().equals("材料,xc")) {
							OutPutUtils.addcell(table, "现场照片", 0, 0, true, contextFont);
						}else{
							OutPutUtils.addcell(table, "货单照片", 0, 0, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (two) {
						if (dPictureList.get((3 * i) + 1).getPLabel().equals("材料,xc")) {
							OutPutUtils.addcell(table, "现场照片", 0, 0, true, contextFont);
						}else{
							OutPutUtils.addcell(table, "货单照片", 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "名称", 0, 0, true, contextFont);
					if (three) {
						if (dPictureList.get((3 * i) + 2).getPLabel().equals("材料,xc")) {
							OutPutUtils.addcell(table, "现场照片", 0, 0, true, contextFont);
						}else{
							OutPutUtils.addcell(table, "货单照片", 0, 0, true, contextFont);
						}
//						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPLabel(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}


					//堆放点
					OutPutUtils.addcell(table, "堆放点", 0, 0, true, contextFont);
					if (one) {
						if (cArrivalRecordEntity.getGuid().equals(dPictureList.get(3 * i).getPPGuid())) {
							OutPutUtils.addcell(table, cArrivalRecordEntity.getSPName(), 0, 0, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "堆放点", 0, 0, true, contextFont);
					if (two) {
						if (cArrivalRecordEntity.getGuid().equals(dPictureList.get((3 * i) + 1).getPPGuid())) {
							OutPutUtils.addcell(table, cArrivalRecordEntity.getSPName(), 0, 0, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "堆放点", 0, 0, true, contextFont);
					if (three) {
						if (cArrivalRecordEntity.getGuid().equals(dPictureList.get((3 * i) + 2).getPPGuid())) {
							OutPutUtils.addcell(table, cArrivalRecordEntity.getSPName(), 0, 0, true, contextFont);
						}
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}


					//照片来源：相册or相机
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "来源", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPPResour(), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}

					//时间
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (one) {
						OutPutUtils.addcell(table, dPictureList.get(3 * i).getPTime() == null ? "" : DateUtils.format(dPictureList.get(3 * i).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (two) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 1).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 1).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
					OutPutUtils.addcell(table, "时间", 0, 0, true, contextFont);
					if (three) {
						OutPutUtils.addcell(table, dPictureList.get((3 * i) + 2).getPTime() == null ? "" : DateUtils.format(dPictureList.get((3 * i) + 2).getPTime(), "yyyy-MM-dd"), 0, 0, true, contextFont);
					} else {
						OutPutUtils.addcell(table, "", 0, 0, true, contextFont);
					}
				}
				document.add(table);
			}

		}
	}








	
}
